package com.algorithm.base.greedy;

/**
 * 860. 柠檬水找零
 *
 * @author Amadeus
 * @date 2023/11/23
 */
public class LemonadeChange {

    public boolean lemonadeChange(int[] bills) {
        int five = 0;
        int ten = 0;
        for (int bill : bills) {
            if (bill == 5) {
                five++;
            } else if (bill == 10) {
                five--;
                if (five < 0) {
                    return false;
                }
                ten++;
            } else {
                if (ten > 0) {
                    ten--;
                    five--;
                    if (five < 0) {
                        return false;
                    }
                } else {
                    five -= 3;
                    if (five < 0) {
                        return false;
                    }
                }
            }
        }
        return true;
    }

}
